import React, { useEffect, useState } from 'react'

export default function Cat() {
    let [x, setX] = useState(100);
    let [y, setY] = useState(100);
    function move(e){
        console.log('e: ', e.clientX, e.clientY);
        setX(e.clientX);
        setY(e.clientY);
    }
    useEffect(()=>{//componentDidMount
        // 绑定自定事件
        window.addEventListener('mousemove', move)
        return ()=>{
            window.removeEventListener('mousemove', move)
        }
    },[])
    return (
        <div style={
            {
                width: 100,
                height: 100,
                background: 'pink',
                position: 'absolute',
                left: x,
                top: y
            }
        }>Cat</div>
    )
}
